package com.label.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.label.entity.Log;
import com.label.entity.User;
import com.label.mapper.LabelsMapper;
import com.label.mapper.UserMapper;
import com.label.service.LogService;
import com.label.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jianhua
 * @since 2022-03-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    HttpSession session;
    @Autowired
    private UserMapper userMapper;
@Override
    public Page pageList(Page page, User user){
    if (page==null){
        page =new Page();
    }
    QueryWrapper wrapper=new QueryWrapper();
    if (user!=null&& StringUtils.isNotEmpty(user.getUsername())){
        wrapper.like("username",user.getUsername());
    }
    return super.page(page,wrapper);
}
    @Override
    public boolean login(User user) {
        String username = user.getUsername();
        String password = user.getPassword();
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        User user1=userMapper.selectOne(queryWrapper);
        if(user1!=null&&password.equals(user1.getPassword())){
            return true;
        }
        return false;
    }
    @Override
    public boolean select(String username){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        User user1=userMapper.selectOne(queryWrapper);
        if(user1!=null){
            return true;
        }
        return false;
    }
}
